package edu.yuhf.dao.oracle;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.yuhf.db.utils.JdbcTemplate;

import edu.yuhf.dao.iface.PermissionDao;
import edu.yuhf.domain.Permission;

public class PermissionOracleDaoImpl implements PermissionDao{

	@Override
	public List<Permission> getPermissions(String userName) {
		String sql="select p.id,p.permission,p.url,p.remark from users u left outer join userRole ur on u.id=ur.userId" + 
				"    left outer join permissionRole pr on ur.roleid=pr.roleId" + 
				"    left outer join permission p on pr.permissionId=p.id" + 
				"    where u.name=?";
		List<Permission> list=JdbcTemplate.query(sql, (rs)->{
			List<Permission> list0=new ArrayList<>();
			try {
				while(rs.next()) {
					Permission permission=new Permission(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4));
					list0.add(permission);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return list0;
		}, new Object[] {userName});
		return list;
	}

}
